package com.hmjk.health.views;

import com.hmjk.health.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ScheduleGatherView extends LinearLayout{
	private Context mContext;
	private LinearLayout mWaitView;
	private LinearLayout mEmptyView;
	private boolean indicationiconflag = true;
	private LinearLayout mDetailView;
	
	public ScheduleGatherView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public ScheduleGatherView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
	public ScheduleGatherView(Context context) {
		super(context);
		init(context);
	}
	
	private void init(Context context){
		mContext = context;
		LayoutInflater inflater = LayoutInflater.from(context);
		mWaitView = (LinearLayout)inflater.inflate(R.layout.health_schedule_wait_view, null);
		mEmptyView = (LinearLayout)inflater.inflate(R.layout.health_schedule_wait_view, null);
		mDetailView = (LinearLayout)inflater.inflate(R.layout.health_schedule_detail_view, null);
	//	addView(mWaitView, 0);
	}
	
	public void setLoading(boolean show){
		if(show){
			mWaitView.setVisibility(View.VISIBLE);
		}else{
			mWaitView.setVisibility(View.GONE);
		}
	}
	
	public void clearAll(){
		int count = getChildCount();
		if(count > 1)
			removeViews(1, count-1);
		
		indicationiconflag = true;
	}
	
	public void checkEmpty(){
		int count = getChildCount();
		if(count < 2)
			addView(mEmptyView);
	}
	
	public void hasMore(View.OnClickListener listener){
		if(listener != null){
		addView(mDetailView);
		mDetailView.setOnClickListener(listener);
		}
	}
	
	public void addDateView(String date){
		LayoutInflater inflater = LayoutInflater.from(mContext);
		RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.health_schedule_date_view, null);
		TextView datetext = (TextView) view.findViewById(R.id.todolist_date);
		
		if(date.equalsIgnoreCase("today")){
			datetext.setText(R.string.addr_today);
		}else if(date.equalsIgnoreCase("yesterday")){
			datetext.setText(R.string.addr_yesterday);
		}else{
			datetext.setText(date);
		}
		addView(view);
	}
	
	public void addAddressView(int type,String timestr,String infostr, String memostr){
		LayoutInflater inflater = LayoutInflater.from(mContext);
		LinearLayout view = (LinearLayout) inflater.inflate(R.layout.health_schedule_todo_view, null);
		TextView timetext = (TextView) view.findViewById(R.id.todolist_time);
		timetext.setText(timestr);
		TextView timeinfo = (TextView) view.findViewById(R.id.todolist_info);
		timeinfo.setText(infostr);
		TextView memeotext = (TextView) view.findViewById(R.id.todolist_memo);
		memeotext.setText(memostr);
        int res_id;
        switch(type)
        {
        case 0:
        	res_id =R.drawable.health_time_icon;
        break;
        
        default:
        	res_id =R.drawable.health_time_icon;
        break;	
        
        }
		ImageView alarmtypeicon = (ImageView) view.findViewById(R.id.todolist_type_icon);

		alarmtypeicon.setImageResource(res_id);
		
		ImageView icon = (ImageView) view.findViewById(R.id.todolist_indication_icon);
		
		if(indicationiconflag){
			icon.setImageResource(R.drawable.health_schedule_point);
			view.setBackgroundResource(R.color.TODOLIST_TEXT_BACKGROUND0);
		}else{
			icon.setImageResource(R.drawable.health_schedule_point_cur);
			view.setBackgroundResource(R.color.TODOLIST_TEXT_BACKGROUND1);
		}
		indicationiconflag = !indicationiconflag;
		addView(view);
	}
}
